<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of class
 *
 * @author Андрей
 */
class CommentsModel extends Model{

    function __construct() {
        parent::__construct();
    }
    public function getAllCommentsOfPage($page) {
        return $this->db->query("SELECT *, DATE_FORMAT(FROM_UNIXTIME(date), '<span class=\"year\">%d.%m.%y</span> <b>%H:%I:%S</b>') as n_date FROM comments WHERE page = '".$page."'");     
    }
    public function getAllCommentsOfPagePager($page, $from, $to) {
        $res = $this->db->query("SELECT * FROM comments WHERE page = '".$page."' LIMIT ".$from.",".$to."");    
        return $res->rows;    
    }
    public function getNumOfCommentsOnPage($page) {
        $total = $this->db->query("SELECT COUNT(*) AS num FROM comments WHERE page = '".$page."'");
        $total = $total->row['num'][0];
        return $total;
    }
    public function addComment($data) {
        $result = $this->db->query("INSERT INTO comments (page, user_id, message) VALUES ('".$data['page']."', '".$data['from']."', '".$data['message']."')");    
        return $result;
    }
    public function getCommentById($id) {
        $data = $this->db->query("SELECT * FROM comments WHERE id_comment='" . $id . "'");
         return $data->row;
    }

}
?>
